<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form class="layui-form" action="changePwd" method="post" style="padding-top:20px;padding-right: 100px;" lay-filter="changePwdForm">
			<div class="layui-form-item">
	    		<label class="layui-form-label">原密码</label>
	    		<div class="layui-input-block">
	      			<input type="password" name="oldPwd" value="${model.name}" lay-verify="required" required autocomplete="off" placeholder="请输入新密码" class="layui-input">
	    		</div>
	  		</div>
			<div class="layui-form-item">
	    		<label class="layui-form-label">新密码</label>
	    		<div class="layui-input-block">
	      			<input id="newPwd" type="password" name="newPwd" value="${model.name}" lay-verify="required|pwdConfirm" required autocomplete="off" placeholder="请再次输入新密码" class="layui-input">
	    		</div>
	  		</div>
			<div class="layui-form-item">
	    		<label class="layui-form-label">密码确认</label>
	    		<div class="layui-input-block">
	      			<input id="newPwd2" type="password" name="newPwd2" value="${model.name}" lay-verify="required" required autocomplete="off" placeholder="请输入名称" class="layui-input">
	    		</div>
	  		</div>
	  		<div class="layui-form-item" style="text-align: right;">
	  			<button class="layui-btn" type="submit" lay-submit lay-filter="changePwdForm1">提交</button>
	  			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	  		</div>
	</form>
	<script type="text/javascript">
	layui.use('form',function(){
		
	form=layui.form;
		form.verify({
			pwdConfirm:function(value,item){
				if($('#newPwd2').val()!=$('#newPwd').val()){
					$('#newPwd').val('');
					$('#newPwd2').val('');
					return "两次输入的新密码不一致，请重新输入";
				}
			}
		});
		
	    form.on('submit(changePwdForm1)', function(data){
	        //console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
	        //console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
	        //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
	        $.post('changePwd',data.field,function(result){
	        	if(result.success){
	        		window.location.href="logout";
	        	}else{
	        		layer.alert(result.msg);
	        	}
	        });
	        
	        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	      });
	});	
	            
	</script>
</body>
</html>